﻿using System.Data;
using ET;
namespace DAL
{
    public class Order_Buy_Detail_DAL : clsConnect
    {
        private static readonly clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetDataOrderBuyTemp(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Users_Id", id);
            return cls.GetData("sp_tb_Order_Buy_Detail_Temp");
        }
        public DataTable GetDataOrderBuyTempQuality(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id",id);
            return cls.GetData("sp_tb_Order_Buy_Detail_Temp_Edit");
        }
        public DataTable GetDataOrderBuyEditQuality(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Buy_Detail_Id", id);
            return cls.GetData("sp_tb_Order_Buy_Detail_Quality_Edit");
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertOrderBuyDetailTemp(Order_Buy_Detail_Temp data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);

            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);

            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);

            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            cls.AddParameter("@Users_Id", data.Users_Id);
            return cls.ExecuteNonQuery("sp_tb_Order_Buy_Detail_Temp_Insert");
        }
        public bool InsertOrderDetail(ET_Order_Buy_Detail data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Buy_Id", data.Order_Buy_Id);
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);

            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);

            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);

            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@IsActive", data.IsActive);
            return cls.ExecuteNonQuery("sp_tb_tb_Order_Buy_Detail_Insert");
        }
        public bool InsertOrderBuyDetailMaterial(ET_Order_Buy_Detail data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Buy_Id", data.Order_Buy_Id);
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            return cls.ExecuteNonQuery("sp_tb_Order_Buy_Detail_Material_Insert");
        }
        //Update Quality Temp
        public bool UpdateOrderQualityDetail(Order_Buy_Detail_Temp data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", data.Order_Detail_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);
            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);
            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);
            return cls.ExecuteNonQuery("sp_tb_Order_Buy_Detail_Temp_UpdateQuality");
        }
        //Update Quality Detail
        public bool UpdateOrderQualityOrderBuyDetail(ET_Order_Buy_Detail data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Buy_Detail_Id", data.Order_Buy_Detail_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);
            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);
            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);
            return cls.ExecuteNonQuery("sp_tb_Order_Buy_Detail_UpdateQuality");
        }
        public bool DeleteOrderDetail(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            return cls.ExecuteNonQuery("sp_tb_Order_Del");
        }
        #endregion

        #region[Sum-Total]
        public DataTable SumOrderBuyDetailEdit(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Buy_Id", id);
            return cls.GetData("sp_tb_Order_Buy_Detail_Sum_Edit");
        }
        public DataTable SumOrderBuyDetailTemp()
        {
            cls.CreateNewSqlCommand();
            return cls.GetData("sp_tb_Order_Buy_Detail_Sum_Temp");
        }
        #endregion

        #region[Check-Del]
        public bool CheckDelOrder(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Buy_Id", id);
            var dtCheckDel = cls.GetData("sp_Check_tb_Order_Buy");
            if (dtCheckDel.Rows.Count > 0)
                return true;
            return false;
        }
        #endregion
    }
}